home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_amanda.idb / usr / freeware / bin / amoverview.z / amoverview
Encoding:
Text File  |  1999-07-16  |  4.0 KB  |  161 lines

  1. #!/usr/bin/perl5
  2.  
  3. # Catch for sh/csh on systems without #! ability.
  4. eval '(exit $?0)' && eval 'exec /usr/bin/perl5 -S $0 ${1+"$@"}'
  5.     & eval 'exec /usr/bin/perl5 -S $0 $argv:q'
  6.         if 0;
  7.  
  8. require 5.001;
  9.  
  10. use FileHandle;
  11. use Getopt::Long;
  12. use Carp;
  13. use POSIX;
  14.  
  15. sub Usage {
  16.     print STDERR <<END;
  17. Usage: $0 [-config CONFIG] [-verbose]
  18.  
  19. This script generates to standard output an overview of the filesystems
  20. dumped over time and the type of dump done on a particular day, such as
  21. a full dump, or an incremental, or if the dump failed.
  22.  
  23. You may override the default configuration `DailySet1' by using
  24. the -config command line option.  On larger installations, this script
  25. will take a while to run.  In this case, run it with --verbose to see
  26. how far along it is.
  27. END
  28.     exit 1;
  29. }
  30.  
  31. # Default paths for this installation of Amanda.
  32. my $prefix='/usr/freeware';
  33. my $exec_prefix="${prefix}";
  34. my $libexecdir="/usr/freeware/libexec";
  35. my $sbindir="/usr/freeware/bin";
  36.  
  37. # The directory where configurations can be found.
  38. my $confdir="/usr/freeware/etc/amanda";
  39.  
  40. # The default configuration.
  41. my $config="DailySet1";
  42.  
  43. # Get the version suffix.
  44. my $USE_VERSION_SUFFIXES = 'no';
  45. my $suf = '';
  46. if ( $USE_VERSION_SUFFIXES =~ /^yes$/i ) {
  47.     $suf='-2.4.1p1';
  48. }
  49.  
  50. my $amadmin    = "$sbindir/amadmin$suf";
  51.  
  52. # overrideable defaults
  53. my $opt_config        = "$config";
  54. my $opt_hostwidth    = 8;
  55. my $opt_diskwidth    = 20;
  56. my $opt_verbose        = 0;
  57.  
  58. GetOptions('config=s'        => \$opt_config,
  59.        'hostwidth=i'    => \$opt_hostwidth,
  60.        'diskwidth=i'    => \$opt_diskwidth,
  61.        'verbose'        => \$opt_verbose)
  62. or Usage();
  63.  
  64. -d "$confdir/$opt_config" or
  65.     die "$0: directory `$confdir/$opt_config' does not exist.\n";
  66.  
  67.  
  68. # read disklist
  69. my $disklist = "$confdir/$opt_config/disklist";
  70. my %disks = ();
  71. $::host = '';
  72. $::disk = '';
  73. my ($type, $spindle);
  74. my $dlfh = new FileHandle $disklist or
  75.     die "$0: unable to open `$disklist' for reading: $!\n";
  76. while (<$dlfh>) {
  77.     chomp;
  78.     next if /^#/;
  79.     ($host, $disk, $type, $spindle) = split ' ', $_;
  80.     next unless $host;
  81.     $disks{$host}{$disk}++;
  82. }
  83.  
  84. $dlfh->close or
  85.     die "$0: error in closing `$disklist': $!\n";
  86.  
  87. # Get backup dates
  88. %::dates = ();
  89. %::level = ();
  90. $::level = '';
  91. my ($date, $tape, $file, $status);
  92. $opt_verbose and
  93.     print STDERR "Running $amadmin $opt_config find\n";
  94. my $fh = new FileHandle "$amadmin $opt_config find|" or
  95.     die "$0: error in opening `$amadmin $opt_config find' pipe: $!\n";
  96. <$fh>;
  97. while (<$fh>) {
  98.     chomp;
  99.     ($date, $host, $disk, $level, $tape, $file, $status) = split ' ', $_;
  100.     next if $date eq 'date';
  101.     next if $date eq 'Warning:';
  102.     next if $date eq 'Scanning';
  103.     next if $date eq "";
  104.     if ($date =~ /^\d\d\d\d-\d\d-\d\d$/) {
  105.     defined($level{$host}{$disk}{$date}) or
  106.         $level{$host}{$disk}{$date} = '';
  107.     $level{$host}{$disk}{$date} .= ($status eq 'OK') ? $level : 'E';
  108.     $dates{$date}++;
  109.     }
  110.     else {
  111.     print "bad date $date in $_\n";
  112.     }
  113. }
  114. $fh->close or
  115.     die "$0: error in closing `$amadmin $opt_config find|' pipe: $!\n";
  116.  
  117. # touch all the dates just in case whole days were missed.
  118. {
  119.     my ($start, $finish) = 
  120.     map {
  121.         my($y,$m,$d) = split /-/, $_;
  122.         POSIX::mktime(0,0,0,$d,$m-1,$y-1900);
  123.     } (sort keys %dates)[0,-1];
  124.  
  125.     while ($start < $finish) {
  126.     my @l = localtime $start;
  127.     $dates{sprintf("19%2d-%02d-%02d", $l[5], $l[4]+1, $l[3])}++;
  128.     $start += 86400;
  129.     }
  130. }
  131.     
  132.  
  133. # make formats
  134.  
  135. my $top_format = "format TOP =\n\n" .
  136.     sprintf("%-0${opt_hostwidth}s %-0${opt_diskwidth}s ", '', 'date') .
  137.     join(' ', map((split(/-/, $_))[1], sort keys %dates)) . "\n" .
  138.     sprintf("%-0${opt_hostwidth}s %-0${opt_diskwidth}s ", 'host', 'disk') .
  139.     join(' ', map((split(/-/, $_))[2], sort keys %dates)) . "\n" .
  140.     "\n.\n";
  141.  
  142. my $out_format = "format STDOUT =\n" .
  143.     "@" . "<" x ($opt_hostwidth - 1) . ' ' .
  144.     "@" . "<" x ($opt_diskwidth - 1) . ' ' .
  145.     '@> ' x scalar(keys %dates) . "\n" .
  146.     join(', ', '$host', '$disk', 
  147.      map("\$level{\$host}{\$disk}{'$_'}", sort keys %dates)) . "\n" .
  148.     ".\n";
  149.  
  150. eval $top_format;
  151. die $@ if $@;
  152. $^ = 'TOP';
  153. eval $out_format;
  154. die $@ if $@;
  155.  
  156. for $host (sort keys %disks) {
  157.     for $disk (sort keys %{$disks{$host}}) {
  158.     write;
  159.     }
  160. }
  161.